home *** CD-ROM | disk | FTP | other *** search
- /* debughelp.c (c) 1999 by Volker Remuß, remuss@cs.tu-berlin.de */
-
- #include <stdio.h>
-
- #define COLUMNS 12
-
- void hexdump (unsigned char *buf, int cnt)
- /* output of complete buffer in hex and as far as possible as human readable */
- {
- int i, nochncnt=0;
- unsigned char nochnbuf[COLUMNS*4+10];
-
- for (i=0; i < cnt; i++)
- {
- printf("%2hx ", buf[i]);
-
- if ((buf[i] >= ' ') && (buf[i] <='~')) // readable character? if not write a . instead
- nochnbuf[nochncnt++] = buf[i];
- else
- nochnbuf[nochncnt++] = '.';
-
- if ((nochncnt) > (COLUMNS - 1))
- {
- nochnbuf[nochncnt] = 0;
- printf(" %s\n", nochnbuf);
- nochncnt = 0;
- }
- }
-
- if (nochncnt)
- {
- nochnbuf[nochncnt] = '\0';
- for (i=(COLUMNS-nochncnt); i > 0; i--) printf(" ");
- printf(" %s\n", nochnbuf);
- }
- }
-